class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            list: [],
            cate: [],
            name: '',
            pwd: '',
            confirmpwd: '',
            role: '',
            id: 0,
            start: 0,
            pagesize: 15,
            counts: [],
        };
    }

    formatlist(list) {
        var listitem = [], { fundnamearr } = this.state, fundname = '无', fundnamepuah = [];
        list.forEach((x, i) => {
            let fundincome=0,usertotal=0
            if (x.orderlist.length > 0) {
                x.orderlist.forEach(y => {
                    if(y.state=='SHARE_SUCCESS'||y.state=='REDEEM'){
                        fundincome+=((y.newnetworth-y.networth)*y.share)
                      }
                })
                usertotal=(((x.quota+x.storage)/100.00)+(fundincome/10000.00)).toFixed(2)
                fundincome=(fundincome/10000.00).toFixed(2)
            }
            listitem.push(
                <tr key={i}>
                    <td>
                        <div className="customer">
                            <img src={x.item.avatarUrl} />
                            <p>{x.item.nickName}</p>
                        </div>
                    </td>
                    <td>{x.item.phone == null ? '无' : x.item.phone}</td>
                    <td>{usertotal}</td>
                    <td>{(x.storage/100).toFixed(2)}</td>
                    <td>{fundincome}</td>
                    <td>{(x.quota/100).toFixed(2)}</td>
                    <td>{(x.income/100).toFixed(2)}</td>
                    <td>{(x.withdrawal/100).toFixed(2)}</td>
                    <td className="operatebox">
                        <div className='operate' id={"ope" + x.item.id}>
                            <div>
                                <img src="./src/todetails.png" />
                                <p className="edit" onClick={this.todetails.bind(this, x.item.id)}>详情</p>
                            </div>
                            {/* <div>
                                <img src="./src/del.png" />
                                <p className='edit colred' onClick={this.del.bind(this, x.id)}>删除</p>
                            </div> */}


                        </div>
                    </td>
                </tr>
            )
        });
        this.setState({ listitem, list, originallist: list })
    }
    todetails(e) {
        window.location.href = "./userdetail.html?id=" + e;
    }
    // 删除
    // del(e) {
    //     this.setState({ delid: e }, () => {
    //         $('#myModal').modal('toggle');
    //     })
    // }
    // confirmdel() {
    //     let { delid, start, pagesize } = this.state
    //     Backuserdeluser({ id: delid, start, pagesize }, res => {
    //         if (res.issuccess == 1) {
    //             alert('删除成功')
    //             $('#myModal').modal('toggle');
    //             this.freshlist(start)
    //         } else {
    //             $('#myModal').modal('toggle');
    //             alert(res.msg);
    //         }
    //     })
    // }


    componentDidMount() {
        let that = this
        // getfundnamelist(res=>{
        //     if(res.issuccess==1){
        //         that.setState({fundnamearr:res.list},()=>{
        that.freshlist(0)
        //         })
        //     }
        // })


    }
    freshlist(start) {
        let { pagesize } = this.state;
        getuserlist({ pagesize, start }, res => {
            if (res.issuccess == 1) {
                if (start == 0) {
                    let pagecount = Math.ceil(res.total / pagesize);
                    this.setpager(pagecount, start);
                    this.setState({ start, total: res.total })
                }
                this.formatlist(res.list);
            }
        })

    }
    setpager(pagecount, start) {
        let counts = [];
        for (let i = 1; i < pagecount + 1; i++) {
            counts.push(start + i)
        }
        this.setState({ counts, pagestart: 0 })
    }
    clickpage(e) {
        let { start, pagesize, state } = this.state
        start = e * pagesize
        this.setState({ pagestart: e, start }, () => {
            this.freshlist(start, state)
        })
    }
    setpage(e) {
        let { pagesize, cid, start } = this.state
        pagesize = parseInt(e)
        // console.log(pagesize,'pagesizepagesizepagesize');
        this.setState({ pagesize }, () => {
            this.freshlist(start, cid)
        })
    }
    inputchange(prop, e) {
        console.log(prop, 'prop')
        console.log(e.target.value, 'eeee')
        // let { target } = this.state;
        // target[prop] = e.target.value
        // this.setState({ target })
        this.setState({ [prop]: e.target.value })
    }
    add() {
        $('#modalOne').modal('toggle');
    }
    render() {
        let { listitem, counts, pagestart, } = this.state;

        return (
            <div className="breadLinebox">
                {/* <Modal content='确定要删除吗？' click={this.confirmdel.bind(this)} /> */}
                <div className='content_wrap panel-default content_wrap'>
                    <div className="breadLine">
                        <div className="img">
                            <img src='./src/lm_order1.png' />
                            用户管理
                        </div>
                    </div>
                    <div className="content">
                    <div className="tabletit" >
                        
                            {/* <p className="add" onClick={this.add.bind(this)} style={{ cursor: 'pointer' }}>新建</p> */}
                        </div>
                        <table className="tab">
                            <thead>
                                <tr>
                                    <th className="tconter">头像昵称</th>
                                    <th>电话</th>
                                    <th>账户资产</th>
                                    <th>持有基金</th>
                                    <th>基金收益</th>
                                    <th>可转额度</th>
                                    <th>进账</th>
                                    <th>已提现</th>
                                    <th className="cz tconter">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {listitem}
                            </tbody>
                        </table>
                        <div className="pagerbox">
                            <p>共{this.state.total}条</p>
                            <Pager counts={counts} click={this.clickpage.bind(this)} change={this.setpage.bind(this)} index={pagestart} />
                        </div>
                    </div>
                </div>
            </div>


        )


    }
}





ReactDOM.render(
    <div>
        <TopLine />
        <div id='body'>
            <LeftMenu code='user' />
            <Main />
        </div>
    </div>
    // <Barrage/>
    , $('.container')[0]
)